type DownloadByALink = {
    url: string,
    /** 下载的文件名，需携带扩展名 */
    fileName: string,
    notice?: boolean,
};

/**
 * @param {DownloadByALink} reqConf
 * @returns
 */
export function downloadByALink(reqConf) {
    const { notice = true } = reqConf;
    if (!reqConf) return;

    const a = document.createElement("a");
    a.href = reqConf.url;
    // if (!reqConf.fileName) reqConf.fileName = Date.now() + '';
    a.download = reqConf.fileName;

    false &&
        a.addEventListener("click", function () {
            // 下载开始时发送通知
            notice && sendNotification("下载开始", "文件正在下载中...");

            // 下载完成时发送通知
            // TODO: 不执行
            a.addEventListener("load", () => {
                notice && sendNotification("下载完成", "文件下载已完成");
            });
        });
    // notice && message.success(`【${reqConf.fileName || "文件"}】开始下载...`);

    a.click();
    a.remove();
}
